<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <div>
        <input type="checkbox" id="apple"><span>苹果-</span><span>10</span>元
        <input type="number" value="1" min="0">
    </div>
    <div>
        <input type="checkbox" id="putao"><span>葡萄-</span><span>16</span>元
        <input type="number" value="1" min="0">
    </div>
    <p>
        总价：<span>0</span> 元
    </p>
    <input type="checkbox" id="all">全选
</body>
<script>
    $(function () {
        $('div :checkbox,[name="num"]').change(function () {
            var total = 0
            $('div :checkbox').each(function () {
                if ($(this).prop('checked')) {
                    var price = $(this).next().next().html()
                    var num = $(this).next().next().next().val()
                    total += (price * num)
                }
            })
            $('span').last().html(total)
        })
        $('#all').change(function () {
            $('div :checkbox').prop('checked', $(this).prop('checked'))
            $('div :checkbox').change()
        })
    })
</script>

</html>